{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from matplotlib import pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from pathlib import Path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "p = Path('.')\n",
    "\n",
    "for kappa in [1, 2, 4, 8]:\n",
    "\tdf = {}\n",
    "\tfor csv_file in p.glob(f\"k={kappa}*.csv\"):\n",
    "\t\t_, method = csv_file.stem.split('-')\n",
    "\t\tcsv = pd.read_csv(csv_file, usecols=['Value'])\n",
    "\t\tdf[method] = csv.values.squeeze()\n",
    "\t\t# break\n",
    "\n",
    "\tdf = pd.DataFrame(df)\n",
    "\tordered_columns = ['Data', 'Res', 'Jac', 'Desc']\n",
    "\tstyles = ['bs-','ro-','y^-']\n",
    "\tdf = df[ordered_columns]\n",
    "\tdf.rename(columns={'Desc':'$\\mathcal{L}_{\\mathcal{D}_3}$', 'Res':'$\\mathcal{L}_{\\\\text{res}}$', 'Data':'$\\mathcal{L}_{\\\\text{data}}$', 'Jac':'$\\mathcal{L}_{\\mathcal{J}_3}$'}, inplace=True)\n",
    "\tax = df.plot(\n",
    "\t\tfigsize=(14, 6),\n",
    "\t\tlogy=True,\n",
    "\t\tfontsize=18,\n",
    "\t\tgrid=True,\n",
    "\t\tlinewidth=3,\n",
    "\t\t# style=styles\n",
    "\t)\n",
    "\tax.set_title(f'Validation Errors of $\\lambda = {kappa}$', fontsize=25)\n",
    "\tax.set_xlabel('Epochs', fontsize=\t20)\n",
    "\tax.set_ylabel('$L_2$', \tfontsize=\t20)\n",
    "\t\n",
    "\tplt.xticks(fontsize=12)\n",
    "\tplt.yticks(fontsize=12)\n",
    "\tax.legend(df.columns, \tfontsize=\t20, title_fontsize=20, ncol=2)\n",
    "\n",
    "\t# Show the plot\n",
    "\tplt.tight_layout()\n",
    "\n",
    "\tplt.savefig(f'./Val-{kappa}.png')\n",
    "\tplt.close()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
